home *** CD-ROM | disk | FTP | other *** search
-
-
- #include <Errors.h>
- #include <QuickDraw.h>
- #include <Windows.h>
-
- #include "FinderStuff.h"
- #include "FinderDrag.h"
- #include "Spaces.h"
-
- #include <Icons.h>
-
- // —————————————————————————————————————————————————————————————————————————
- // —————————————————————————————————————————————————————————————————————————
- // GetSpaceRect
-
- void GetSpaceRect(WindowPtr win, short spaceIndex, Rect *rct)
- {
- WindowDataHandle winData;
-
- winData = (WindowDataHandle) GetWRefCon(win);
- if (winData != NULL)
- *rct = ((**winData).space)[spaceIndex].spaceRect;
- }
-
-
- // —————————————————————————————————————————————————————————————————————————
- // —————————————————————————————————————————————————————————————————————————
- // WhichSpace determines where the drop has taken place. This app only
- // has two spaces, and after doing a compare it will return the space
- // number, or kNoSpace if it didn't land in a space.
-
- short WhichSpace(WindowPtr win, Point localPt)
- {
- short count, theSpace;
- WindowDataHandle winData;
-
- winData = (WindowDataHandle) GetWRefCon(win);
- theSpace = kNoSpace;
-
- if (winData != NULL) {
- for (count = 0; count < kNumberOfSpaces; count ++) {
- Rect rct;
-
- GetSpaceRect(win, count, &rct);
- if (PtInRect(localPt, &rct))
- theSpace = count;
- }
- }
-
- return theSpace;
- }
-
-
- // —————————————————————————————————————————————————————————————————————————
- // —————————————————————————————————————————————————————————————————————————
- // SendSetterToSelf
-
- OSErr SendSetterToSelf(short spaceNum, WindowPtr win, FSSpecPtr hfsObj)
- {
- AppleEvent send;
- AEDesc selfTarget;
- ProcessSerialNumber psn;
- long longSpaceNum;
- OSErr err;
-
- longSpaceNum = spaceNum;
- selfTarget.dataHandle = NULL;
- send.dataHandle = NULL;
-
- (void) GetCurrentProcess(&psn);
- err = CreateAETarget(&psn, &selfTarget);
- if (err != noErr) goto BailOut;
-
- err = MakeAppleEvent(kPrivateEventClass, kAESetSpace,
- &selfTarget, &send);
- if (err != noErr) goto BailOut;
-
- err = AEPutParamPtr(&send, keyWindowOfSpace, typeLongInteger, (Ptr) &win, sizeof(WindowPtr));
- if (err != noErr) goto BailOut;
-
- err = AEPutParamPtr(&send, keyNumOfSpace, typeLongInteger, (Ptr) &longSpaceNum, sizeof(long));
- if (err != noErr) goto BailOut;
-
- err = AEPutParamPtr(&send, keySpecOfSpace, typeFSS, (Ptr) hfsObj, sizeof(FSSpec));
- if (err != noErr) goto BailOut;
-
- err = SendAppleEvent(&send, NULL, kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer);
-
- BailOut:
- if (selfTarget.dataHandle != NULL) (void) AEDisposeDesc(&selfTarget);
- if (send.dataHandle != NULL) (void) AEDisposeDesc(&send);
-
- return err;
- }
-
-
- // —————————————————————————————————————————————————————————————————————————
- // —————————————————————————————————————————————————————————————————————————
- // SendWindowSpaceSetter
-
- void SendWindowSpaceSetter(WindowPtr win, DragReference theDrag, FSSpecPtr hfsObj)
- {
- Point lePoint;
- WindowDataHandle winData;
- GrafPtr oldPort;
- short spaceNum;
- OSErr err;
-
- winData = (WindowDataHandle) GetWRefCon(win);
-
- if (winData != NULL) {
- GetPort(&oldPort);
- SetPort(win);
- GetDragMouse(theDrag, &lePoint, 0L);
- GlobalToLocal(&lePoint);
- spaceNum = WhichSpace(win, lePoint);
- SetPort(oldPort);
-
- if (spaceNum != kNoSpace)
- err = SendSetterToSelf(spaceNum, win, hfsObj);
- }
- else
- Debugger();
- }
-
-
- // —————————————————————————————————————————————————————————————————————————
- // —————————————————————————————————————————————————————————————————————————
- // SetSpaceIndex
-
- void SetSpaceIndex(WindowPtr win, short index, FSSpecPtr hfsObj)
- {
- WindowDataHandle winData;
- GrafPtr oldPort;
- short spaceNum;
-
- GetPort(&oldPort);
- SetPort(win);
- spaceNum = index;
- winData = (WindowDataHandle) GetWRefCon(win);
-
- if (spaceNum != kNoSpace) {
- //
- // Drag was dropped in a valid space- set its
- // iconSuite, FSSpec, and its isTaken field
- //
- SpacePtr thisSpace;
- OSErr err;
-
- HLock((Handle) winData);
- thisSpace = &(**winData).space[spaceNum];
-
- if (thisSpace->spaceIsTaken == true) {
- //
- // But first we gotta get rid of the current occupant of
- // this space..
- //
- Handle iconSuite;
-
- iconSuite = thisSpace->spaceIconSuite;
-
- if (iconSuite != NULL)
- DisposeIconSuite(iconSuite, true);
- }
-
- thisSpace->spaceIsTaken = true;
- BlockMoveData(hfsObj, &thisSpace->spaceSpec, sizeof(FSSpec));
- err = GetIconSuiteFromFinder(hfsObj, &thisSpace->spaceIconSuite);
- HUnlock((Handle) winData);
- }
- else
- Debugger();
-
- InvalRect(&win->portRect);
- SetPort(oldPort);
- }
-
-
- // —————————————————————————————————————————————————————————————————————————
- // —————————————————————————————————————————————————————————————————————————
- // GetSpaceIconSuite
-
- void GetSpaceIconSuite(WindowPtr win, short count, Handle *iconSuite)
- {
- WindowDataHandle winData;
-
- winData = (WindowDataHandle) GetWRefCon(win);
- if (winData != NULL)
- *iconSuite = (**winData).space[count].spaceIconSuite;
- }
-
-
- // —————————————————————————————————————————————————————————————————————————
- // —————————————————————————————————————————————————————————————————————————
- // InitSpaces
-
- void InitSpaces(WindowDataHandle winData)
- {
- short index;
- short rctTop, rctLeft;
-
- rctTop = 15; rctLeft = 30;
- for (index = 0; index < kNumberOfSpaces; index ++) {
- SetRect(&((**winData).space)[index].spaceRect, rctLeft, rctTop,
- rctLeft + kSpaceHSize, rctTop + kSpaceVSize);
- ((**winData).space)[index].spaceIconSuite = NULL;
- ((**winData).space)[index].spaceIsTaken = false;
- ((**winData).space)[index].spaceIsSelected = false;
-
- rctTop += kSpaceVSize + 15;
- }
- }
-
-
- // —————————————————————————————————————————————————————————————————————————
- // —————————————————————————————————————————————————————————————————————————
-
- pascal OSErr DoAESetSpace(AppleEvent *ae, AppleEvent *reply, long refCon)
- {
- #pragma unused(reply, refCon)
- OSErr err;
- DescType returnType;
- Size returnSize;
- long whichSpace;
- WindowPtr whichWindow;
- FSSpec hfsObj;
-
- err = AEGetParamPtr(ae, keyWindowOfSpace, typeLongInteger, &returnType,
- (Ptr) &whichWindow, sizeof(WindowPtr), &returnSize);
- if (err != noErr) goto BailOut;
-
- err = AEGetParamPtr(ae, keyNumOfSpace, typeLongInteger, &returnType,
- (Ptr) &whichSpace, sizeof(long), &returnSize);
- if (err != noErr) goto BailOut;
-
- err = AEGetParamPtr(ae, keySpecOfSpace, typeFSS, &returnType,
- (Ptr) &hfsObj, sizeof(FSSpec), &returnSize);
- if (err != noErr) goto BailOut;
-
- SetSpaceIndex(whichWindow, (short) whichSpace, &hfsObj);
-
- BailOut:
- return err;
- }
-
-
-
- // —————————————————————————————————————————————————————————————————————————
- // —————————————————————————————————————————————————————————————————————————
- // GetSpaceSpec returns the FSSpec for the slot (or an error if there ain't
- // one.)
-
- OSErr GetSpaceSpec(WindowPtr win, short spaceIndex, FSSpecPtr theSpec)
- {
- WindowDataHandle windowData;
- SpacePtr leSpace;
- OSErr err;
- Boolean foundIt;
-
- foundIt = false;
- err = noErr;
- windowData = (WindowDataHandle) GetWRefCon(win);
-
- if (windowData != NULL) {
- leSpace = & (**windowData).space[spaceIndex];
-
- if (leSpace->spaceIsTaken == true) {
- foundIt = true;
- BlockMoveData(&leSpace->spaceSpec, theSpec, sizeof(FSSpec));
- }
- }
-
- // If for some reason we didn't get a valid FSSpec, return fnfErr
- if (foundIt == false)
- err = fnfErr;
-
- return err;
- }
-